<?php

class User_IndexController extends Veneer_Controller_Module
{
    protected $_dbArray =array('User');
    protected $_moduleName = 'user';

    function indexAction()
    {
        $this->view->title = "User List";

        $entry = new User();
        $this->view->entries = $entry->fetchAll();
		// listHelper
    }

    function regAction()
    {
/*		$form = new Zend_Form();
		$form->setDataSource($_POST);
		$form->addPage('regForm');
		$form->regForm->addField('username');
        $this->regForm->username->addValidator('Alnum');


$tr = new Zend_Mail_Transport_Sendmail('-freturn_to_me@example.com');
Zend_Mail::setDefaultTransport($tr);

$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('somebody@example.com', 'Some Sender');
$mail->addTo('Email@address.com', 'Receiver');
$mail->setSubject('TestSubject');
$mail->send();
*/
		if($this->getRequest()->isPost()) {
			if($form->isValid()) {
				$data =$form->getData();
				//********* insert data
			}
		}
    }


    function loginAction()
    {
        $this->view->title = "Login";
       if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
			$userObj = new User();
            $filter = new Zend_Filter_Alpha();

            $username = $filter->filter($this->_request->getPost('username'));
            $password = $filter->filter($this->_request->getPost('password'));
	        $user_rec = $userObj->fetchRow("username='".$username."'");	// set site_id
			if( $user_rec->password == sha1($password)) {
				$this->_session->login($user_rec);
				$this->_redirect('/my');
			}
			$this->view->errmsg = "User not found or paaword incorrect";
		}
	}

    function logoutAction()
    {
		$this->_session->logout();
    	$this->_redirect('/');

        // redirect back to the album list unless we have rendered the view

	}


}